package com.my.thread.simple;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.*;

/**
 * 多线程
 */
@Slf4j
public class TheadTest {
    //多线程的3种实现
    @Test
    public void test1() throws ExecutionException, InterruptedException {
        new Thread(new Runnable(){
            @Override
            public void run() {
                log.info("info");
            }
        }).start();

        Runnable runnable = () -> System.out.println("lambada 运行 方法级别");

        new ThreadTest().start();//1
        new Thread(new RunnableTest()).start();//2
        //3 有回调
        FutureTask futureTask = new FutureTask(new FutureTaskTest());
        new Thread(futureTask).start();
        System.out.println(futureTask.get());//获取回调信息
    }



    class ThreadTest extends Thread {

        @Override
        public void run() {
            System.out.println("11");
        }
    }

    class RunnableTest implements Runnable {
        //可以赋值进来
        String exceptionMsg;
        CountDownLatch latch;

        public RunnableTest() {

        }

        public RunnableTest(String exceptionMsg, CountDownLatch latch) {
            this.exceptionMsg = exceptionMsg;
            this.latch = latch;
        }

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "线程执行");
        }
    }

    class FutureTaskTest implements Callable<String> {
        @Override
        public String call() throws Exception {
            return "123";
        }
    }
}
